/*
 * frmPrincipal.java
 *
 * Created on 03/11/2011, 11:44:19
 */
package scc.Telas;

import Dao.UserDAO;
import Entidade.Usuario;
import java.beans.PropertyVetoException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JInternalFrame;
/**
 *
 * @author Davidson
 */
public class frmPrincipal extends javax.swing.JFrame {
        
    private JInternalFrame janelaInternaAlterarSenha;
    private JInternalFrame janelaInternaCadastrarUsuario;
    private JInternalFrame janelaInternaAbrirCaixa;
    private JInternalFrame janelaInternaRelatorioCreditoExterno;
    private JInternalFrame janelaInternaRelatorioSangria;
    private JInternalFrame janelaInternaRelatorioPagamentosDiversos;
    private JInternalFrame janelaInternaReimpressaoRecibos;
    private UserDAO dao;
    private Usuario usuario;
    /** Creates new form frmPrincipal */
    public frmPrincipal(UserDAO dao2, Usuario usuario2) {
        initComponents();
        dao = dao2;
        usuario = usuario2;        
        this.setExtendedState(MAXIMIZED_BOTH);
        this.setIconImage(new javax.swing.ImageIcon(getClass().getResource("/scc/Imagens/currency_dollar_red.png")).getImage());
        if (usuario.getLogin().equals("d")) {
            miCadastrarUsuario.setEnabled(true);
        }
    }   

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDesktop = new javax.swing.JDesktopPane();
        mbPrincipal = new javax.swing.JMenuBar();
        mnCaixa = new javax.swing.JMenu();
        miAbrirCaixa = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        miFecharCaixa = new javax.swing.JMenuItem();
        mnManutencao = new javax.swing.JMenu();
        miManutUsuarios = new javax.swing.JMenuItem();
        miCadastrarUsuario = new javax.swing.JMenuItem();
        mnRelatorios = new javax.swing.JMenu();
        miCreditoExterno = new javax.swing.JMenuItem();
        miSangria = new javax.swing.JMenuItem();
        miPagamentosdiversos = new javax.swing.JMenuItem();
        miReimpressaoRecibos = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jDesktop.setBackground(new java.awt.Color(255, 255, 255));

        mbPrincipal.setPreferredSize(new java.awt.Dimension(91, 38));

        mnCaixa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/scc/Imagens/currency_dollar_red.png"))); // NOI18N
        mnCaixa.setText("Caixa");

        miAbrirCaixa.setText("Abertura de Caixa");
        miAbrirCaixa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miAbrirCaixaActionPerformed(evt);
            }
        });
        mnCaixa.add(miAbrirCaixa);
        mnCaixa.add(jSeparator1);

        miFecharCaixa.setText("Sair");
        miFecharCaixa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miFecharCaixaActionPerformed(evt);
            }
        });
        mnCaixa.add(miFecharCaixa);

        mbPrincipal.add(mnCaixa);

        mnManutencao.setIcon(new javax.swing.ImageIcon(getClass().getResource("/scc/Imagens/gear_red.png"))); // NOI18N
        mnManutencao.setText("Manutenção");
        mnManutencao.setIconTextGap(2);
        mnManutencao.setMaximumSize(new java.awt.Dimension(120, 32));
        mnManutencao.setMinimumSize(new java.awt.Dimension(120, 32));
        mnManutencao.setPreferredSize(new java.awt.Dimension(120, 32));

        miManutUsuarios.setText("Alterar Senha");
        miManutUsuarios.setOpaque(true);
        miManutUsuarios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miManutUsuariosActionPerformed(evt);
            }
        });
        mnManutencao.add(miManutUsuarios);

        miCadastrarUsuario.setText("Cadastrar Usuário");
        miCadastrarUsuario.setEnabled(false);
        miCadastrarUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miCadastrarUsuarioActionPerformed(evt);
            }
        });
        mnManutencao.add(miCadastrarUsuario);

        mbPrincipal.add(mnManutencao);

        mnRelatorios.setIcon(new javax.swing.ImageIcon(getClass().getResource("/scc/Imagens/report_32.png"))); // NOI18N
        mnRelatorios.setText("Relatórios");

        miCreditoExterno.setText("Crédito Externo");
        miCreditoExterno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miCreditoExternoActionPerformed(evt);
            }
        });
        mnRelatorios.add(miCreditoExterno);

        miSangria.setText("Sangria");
        miSangria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miSangriaActionPerformed(evt);
            }
        });
        mnRelatorios.add(miSangria);

        miPagamentosdiversos.setText("Pagamentos Diversos");
        miPagamentosdiversos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miPagamentosdiversosActionPerformed(evt);
            }
        });
        mnRelatorios.add(miPagamentosdiversos);

        miReimpressaoRecibos.setText("Reimpressão de Recibos");
        miReimpressaoRecibos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miReimpressaoRecibosActionPerformed(evt);
            }
        });
        mnRelatorios.add(miReimpressaoRecibos);

        mbPrincipal.add(mnRelatorios);

        setJMenuBar(mbPrincipal);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktop, javax.swing.GroupLayout.DEFAULT_SIZE, 778, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktop, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 494, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void miManutUsuariosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miManutUsuariosActionPerformed
        
        janelaInternaAlterarSenha = frmManutencaoDeUsuarios.getInstancia(dao, usuario);
        if (janelaInternaAlterarSenha.getParent() != jDesktop) {
                jDesktop.add(janelaInternaAlterarSenha);
        }
        janelaInternaAlterarSenha.show();
        janelaInternaAlterarSenha.moveToFront();

    }//GEN-LAST:event_miManutUsuariosActionPerformed

    private void miAbrirCaixaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miAbrirCaixaActionPerformed
        try {                                             
            
            janelaInternaAbrirCaixa = frmCaixa.getInstancia(dao, usuario);
            if (janelaInternaAbrirCaixa.getParent() != jDesktop) {
                    jDesktop.add(janelaInternaAbrirCaixa);
            }
            janelaInternaAbrirCaixa.show();
            janelaInternaAbrirCaixa.moveToFront();
            try {
                janelaInternaAbrirCaixa.setMaximum(true);
            } catch (PropertyVetoException ex) {
                Logger.getLogger(frmPrincipal.class.getName()).log(Level.SEVERE, null, ex);
            }
            
        } catch (SQLException ex) {
            Logger.getLogger(frmPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }//GEN-LAST:event_miAbrirCaixaActionPerformed

    private void miFecharCaixaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miFecharCaixaActionPerformed
        System.exit(0);
    }//GEN-LAST:event_miFecharCaixaActionPerformed

    private void miCadastrarUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miCadastrarUsuarioActionPerformed
        
        janelaInternaCadastrarUsuario = frmCadastrarUsuario.getInstancia(dao, usuario);
        if (janelaInternaCadastrarUsuario.getParent() != jDesktop) {
                jDesktop.add(janelaInternaCadastrarUsuario);
        }
        janelaInternaCadastrarUsuario.show();
        janelaInternaCadastrarUsuario.moveToFront();
        
        
    }//GEN-LAST:event_miCadastrarUsuarioActionPerformed

    private void miCreditoExternoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miCreditoExternoActionPerformed
        janelaInternaRelatorioCreditoExterno = frmRelatorioCreditoExterno.getInstancia(dao);
        if (janelaInternaRelatorioCreditoExterno.getParent() != jDesktop) {
                jDesktop.add(janelaInternaRelatorioCreditoExterno);
        }
        janelaInternaRelatorioCreditoExterno.show();
        janelaInternaRelatorioCreditoExterno.moveToFront();        
    }//GEN-LAST:event_miCreditoExternoActionPerformed

    private void miSangriaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSangriaActionPerformed
        janelaInternaRelatorioSangria = frmRelatorioSangria.getInstancia(dao);
        if (janelaInternaRelatorioSangria.getParent() != jDesktop) {
                jDesktop.add(janelaInternaRelatorioSangria);
        }
        janelaInternaRelatorioSangria.show();
        janelaInternaRelatorioSangria.moveToFront();
    }//GEN-LAST:event_miSangriaActionPerformed

    private void miPagamentosdiversosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miPagamentosdiversosActionPerformed
        janelaInternaRelatorioPagamentosDiversos = frmRelatorioPagamentosDiversos.getInstancia(dao);
        if (janelaInternaRelatorioPagamentosDiversos.getParent() != jDesktop) {
                jDesktop.add(janelaInternaRelatorioPagamentosDiversos);
        }
        janelaInternaRelatorioPagamentosDiversos.show();
        janelaInternaRelatorioPagamentosDiversos.moveToFront();
    }//GEN-LAST:event_miPagamentosdiversosActionPerformed

    private void miReimpressaoRecibosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miReimpressaoRecibosActionPerformed
        janelaInternaReimpressaoRecibos = frmReimpressaoRecibo.getInstancia(dao);
        if (janelaInternaReimpressaoRecibos.getParent() != jDesktop) {
                jDesktop.add(janelaInternaReimpressaoRecibos);
        }
        janelaInternaReimpressaoRecibos.show();
        janelaInternaReimpressaoRecibos.moveToFront();
    }//GEN-LAST:event_miReimpressaoRecibosActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDesktopPane jDesktop;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JMenuBar mbPrincipal;
    private javax.swing.JMenuItem miAbrirCaixa;
    private javax.swing.JMenuItem miCadastrarUsuario;
    private javax.swing.JMenuItem miCreditoExterno;
    private javax.swing.JMenuItem miFecharCaixa;
    private javax.swing.JMenuItem miManutUsuarios;
    private javax.swing.JMenuItem miPagamentosdiversos;
    private javax.swing.JMenuItem miReimpressaoRecibos;
    private javax.swing.JMenuItem miSangria;
    private javax.swing.JMenu mnCaixa;
    private javax.swing.JMenu mnManutencao;
    private javax.swing.JMenu mnRelatorios;
    // End of variables declaration//GEN-END:variables

}